﻿using BaseUi.Device;
using Ping9719.DeviceCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi
{
    /// <summary>
    /// ChangeBoxNewView.xaml 的交互逻辑
    /// </summary>
    public partial class ChangeBoxNewView : UserControl
    {
        public ChangeBan DeviceData1
        {
            get { return (ChangeBan)GetValue(DeviceDataProperty1); }
            set { SetValue(DeviceDataProperty1, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty1 =
            DependencyProperty.Register("DeviceData1", typeof(ChangeBan), typeof(ChangeBoxNewView), new PropertyMetadata(null));
        public int Adder
        {
            get { return (int)GetValue(DeviceDataProperty3); }
            set { SetValue(DeviceDataProperty3, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty3 =
            DependencyProperty.Register("Adder", typeof(int), typeof(ChangeBoxNewView), new PropertyMetadata(null));
        public ChangeBoxNewView()
        {
            InitializeComponent();
        }
        private void change(object sender, RoutedEventArgs e)
        {
            try
            {
                var aaa = new Result<string>();
                switch ((sender as Button).Name)
                {

                    case "sapape1":
                        aaa = DeviceData1.Readsent1(500, Adder);
                        break;
                    case "sapape2":
                        aaa = DeviceData1.Readsent2(500, Adder);
                        break;
                    case "sapape3":
                        aaa = DeviceData1.Readsent3(500, Adder);
                        break;
                    case "sapape4":
                        aaa = DeviceData1.Readsent4(500, Adder);
                        break;
                    case "sapape5":
                        aaa = DeviceData1.Readsent5(500, Adder);
                        break;
                    case "sapape6":
                        aaa = DeviceData1.Readsent6(500, Adder);
                        break;
                    case "sapape7":
                        aaa = DeviceData1.Readsent7(500, Adder);
                        break;
                    case "sapape8":
                        aaa = DeviceData1.Readsent8(500, Adder);
                        break;
                    case "sapape9":
                        aaa = DeviceData1.Readsent9(500, Adder);
                        break;
                    case "sapape10":
                        aaa = DeviceData1.Readsent10(500, Adder);
                        break;
                }

                if (aaa.IsSucceed)
                {
                    textBoxInfo.AppendText($"成功切换页面" + aaa.Value + "\r\n");
                }
                else
                {
                    textBoxInfo.AppendText($"失败：{aaa.Err}\r\n");
                }
            }
            catch (Exception ex)
            {
                textBoxInfo.AppendText($"错误：{ex.Message}\r\n");
            }
        }
    }
}
